type ReplaceAll<
  S extends string,
  From extends string,
  To extends string
> = S extends `${infer F}${From}${infer L}`
  ? `${F}${From extends "" ? "" : To}${ReplaceAll<L, From, To>}`
  : S;

type RA = ReplaceAll<"foofoobar", "foo", "bar">;
